/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-08-03
 * Time: 21:33
 */
public class Solution {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }

        ListNode cur = head.next;
        head.next = null;
        while (cur != null ){
            //保留当前节点的下一节点
            ListNode curN = cur.next;
            //令当前节点头插
            cur.next = head;
            head = cur;

            //下一节点的位置
            cur = curN;
        }
        return head;
    }
}
